package cl.ccs.migracionbcmc.validators;


import cl.ccs.migracionbcmc.validators.exception.ValidatorException;

public class Answer extends Validator{

    public final static String ANSWER_PATTERN = "^[A-Za-z0-9]{3,20}$";
    private String answer;

    public Answer(String answer) throws ValidatorException
    {
        super();
        setAnswer(answer);
        
    }

    private void setAnswer(String answer) throws ValidatorException {
        if (match(answer, ANSWER_PATTERN)) {
            this.answer = answer;
        }
        else {
            throw new ValidatorException("Invalid Answer !");
        }
        this.answer = answer;
    }

    public String getAnswer() {
        return answer;
    }
    
    public static boolean isValid(String a) {
        try {
            Answer answer = new Answer(a);
        }
        catch (ValidatorException ae) {
            return false;   
        }
        return true;
    }
}
